{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "10437a73",
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts.charts import Funnel\n",
    "import pyecharts.options as opts\n",
    "\n",
    "from pyecharts.faker import Faker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2677573b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('哈士奇', 120),\n",
       " ('萨摩耶', 128),\n",
       " ('泰迪', 106),\n",
       " ('金毛', 41),\n",
       " ('牧羊犬', 30),\n",
       " ('吉娃娃', 147),\n",
       " ('柯基', 69)]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list( zip(Faker.choose(), Faker.values()) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "f90c6077",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['草莓', 144],\n",
       " ['芒果', 56],\n",
       " ['葡萄', 127],\n",
       " ['雪梨', 60],\n",
       " ['西瓜', 36],\n",
       " ['柠檬', 129],\n",
       " ['车厘子', 146]]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[list(i)  for i in zip(Faker.choose(), Faker.values())]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f8af90ac",
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"5b444acbe6c340a2918cf95f47317bca\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_5b444acbe6c340a2918cf95f47317bca = echarts.init(\n",
       "                    document.getElementById('5b444acbe6c340a2918cf95f47317bca'), 'white', {renderer: 'canvas'});\n",
       "                var option_5b444acbe6c340a2918cf95f47317bca = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u5546\\u54c1\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u8349\\u8393\",\n",
       "                    \"value\": 110\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8292\\u679c\",\n",
       "                    \"value\": 113\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8461\\u8404\",\n",
       "                    \"value\": 92\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u96ea\\u68a8\",\n",
       "                    \"value\": 146\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u897f\\u74dc\",\n",
       "                    \"value\": 36\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u67e0\\u6aac\",\n",
       "                    \"value\": 52\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8f66\\u5398\\u5b50\",\n",
       "                    \"value\": 99\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 0,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u8461\\u8404\",\n",
       "                \"\\u8f66\\u5398\\u5b50\",\n",
       "                \"\\u8349\\u8393\",\n",
       "                \"\\u8292\\u679c\",\n",
       "                \"\\u96ea\\u68a8\",\n",
       "                \"\\u67e0\\u6aac\",\n",
       "                \"\\u897f\\u74dc\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u8349\\u8393\": true,\n",
       "                \"\\u8292\\u679c\": true,\n",
       "                \"\\u8461\\u8404\": true,\n",
       "                \"\\u96ea\\u68a8\": true,\n",
       "                \"\\u897f\\u74dc\": true,\n",
       "                \"\\u67e0\\u6aac\": true,\n",
       "                \"\\u8f66\\u5398\\u5b50\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6f0f\\u6597\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_5b444acbe6c340a2918cf95f47317bca.setOption(option_5b444acbe6c340a2918cf95f47317bca);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1e3520deb80>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Funnel()\n",
    "    .add('商品', [list(i)  for i in zip(Faker.choose(), Faker.values())])\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='漏斗图'))\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8d382034",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[['访问', 100], ['点击', 80], ['咨询', 60], ['加购', 40], ['下单', 20]]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_data = ['访问', '点击', '咨询', '加购', '下单']\n",
    "y_data = [100, 80, 60, 40, 20]\n",
    "\n",
    "data = [[x_data[i], y_data[i]]  for i in range(len(x_data))]\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "66403060",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"a6c10a18312a4804b593a8631a5ac55c\" style=\"width:600px; height:400px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_a6c10a18312a4804b593a8631a5ac55c = echarts.init(\n",
       "                    document.getElementById('a6c10a18312a4804b593a8631a5ac55c'), 'white', {renderer: 'canvas'});\n",
       "                var option_a6c10a18312a4804b593a8631a5ac55c = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"funnel\",\n",
       "            \"name\": \"\\u6f0f\\u6597\\u56fe\",\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u8bbf\\u95ee\",\n",
       "                    \"value\": 100\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u70b9\\u51fb\",\n",
       "                    \"value\": 80\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u54a8\\u8be2\",\n",
       "                    \"value\": 60\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u52a0\\u8d2d\",\n",
       "                    \"value\": 40\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u4e0b\\u5355\",\n",
       "                    \"value\": 20\n",
       "                }\n",
       "            ],\n",
       "            \"sort\": \"descending\",\n",
       "            \"gap\": 2,\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"inside\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"tooltip\": {\n",
       "                \"show\": true,\n",
       "                \"trigger\": \"item\",\n",
       "                \"triggerOn\": \"mousemove|click\",\n",
       "                \"axisPointer\": {\n",
       "                    \"type\": \"line\"\n",
       "                },\n",
       "                \"showContent\": true,\n",
       "                \"alwaysShowContent\": false,\n",
       "                \"showDelay\": 0,\n",
       "                \"hideDelay\": 100,\n",
       "                \"formatter\": \"{a}<br/> {b}:{c}\",\n",
       "                \"textStyle\": {\n",
       "                    \"fontSize\": 14\n",
       "                },\n",
       "                \"borderWidth\": 0,\n",
       "                \"padding\": 5\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u4e0b\\u5355\",\n",
       "                \"\\u70b9\\u51fb\",\n",
       "                \"\\u54a8\\u8be2\",\n",
       "                \"\\u52a0\\u8d2d\",\n",
       "                \"\\u8bbf\\u95ee\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u8bbf\\u95ee\": true,\n",
       "                \"\\u70b9\\u51fb\": true,\n",
       "                \"\\u54a8\\u8be2\": true,\n",
       "                \"\\u52a0\\u8d2d\": true,\n",
       "                \"\\u4e0b\\u5355\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"showContent\": true,\n",
       "        \"alwaysShowContent\": false,\n",
       "        \"showDelay\": 0,\n",
       "        \"hideDelay\": 100,\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0,\n",
       "        \"padding\": 5\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6f0f\\u6597\\u56fe\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_a6c10a18312a4804b593a8631a5ac55c.setOption(option_a6c10a18312a4804b593a8631a5ac55c);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x1e352838bb0>"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c = (\n",
    "    Funnel(\n",
    "        init_opts=opts.InitOpts(width='600px', height='400px')\n",
    "    )\n",
    "    .add(\n",
    "        series_name='漏斗图',\n",
    "        data_pair=data,\n",
    "        gap=2,  # 间隙\n",
    "        \n",
    "        tooltip_opts=opts.TooltipOpts(\n",
    "            trigger='item',\n",
    "            formatter='{a}<br/> {b}:{c}'\n",
    "        ),\n",
    "        label_opts=opts.LabelOpts(\n",
    "            is_show=True,\n",
    "            position='inside'\n",
    "        )\n",
    "    )\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title='漏斗图'))\n",
    ")\n",
    "c.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f0d5f44a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dce6307b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
